<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8" %>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>开工前管理工具审批新增</title>
</head>
<style>	
	.uploadA{
		color:blue;
		text-decoration: none; 
  		border-bottom: 1px solid blue; 
	}
	.tg-c {
		text-align: center;
	}
	.contract-box {
		width: 100%;
		min-height: 100px;
	}
	
	.contract-money {
		width: 94%;
		margin: 0px auto;
	}
	
	.contract-money .layui-table {
		margin: 0;
	}
	
	.contract-money th {
		text-align: center;
		height: 38px;
	}
	
	.contract-money .label {
		display: block;
		width: 45px !important;
		margin-left: 15px;
	}
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	.layui-legend{
		background-color:#5fb878;
		font-size:15px !important;
		width:160px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width: 180px;}
	}
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
	    <div class="layui-tab-item layui-show">
	    	<div style="padding-top:15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form" lay-filter="add_info_from">
				<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">项目基础信息  ></legend>
				  <div style="margin-top:20px">
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					      	<label class="layui-form-label">申请公司</label>
					      	<div class="layui-input-inline">
					      		<input type="hidden" name="hrOrgid" value="${bindOrgId}">
								<input type="text" value="${bindOrgName}" style="border: 0px;" readonly="readonly" class="layui-input">
					      	</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请部门</label>
				      		<div class="layui-input-inline">
				      			<input type="hidden" name="hrDeptid" value="${bindDeptId}">
								<input type="text" value="${bindDeptName}" style="border:0px;" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请人</label>
				      		<div class="layui-input-inline">
				        		<input type="hidden" name="hrStaffApplyid" readonly="readonly" value="${SESSION_KEY_USER_DETAIL.hrStaffId }">
				        		<input type="text" name="staffname" value="${staffName }" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
				    </div>
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					      	<label class="layui-form-label">项目名称</label>
					      	<div class="layui-input-inline">
					        	<select name="proCodeAndCodes" lay-filter="add_select_proId" lay-verify="required" lay-search>
		              				<option value="">请选择-项目名称</option>
				              		<c:if test="${not empty disclosePros }">
				              			<c:forEach items="${disclosePros}" var="disclosePro">
				              				<option value="${disclosePro.proCode }_${disclosePro.id }_${disclosePro.proName }_${disclosePro.sgCityId }">${disclosePro.proName }</option>
					            		</c:forEach>
				              		</c:if>
				              	</select>						        
					      	</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">项目地点</label>
				      		<div class="layui-input-inline">
						        <input type="hidden" id="id_sgCityId" name="sgCityId" >
						        <input type="text" id="id_sgCityName" name="sgCityName" style="border:0px;" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">总投资额（万元）</label>
				      		<div class="layui-input-inline">
				        		<input type="text" id="id_sumAmount" name="sumAmount" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
				    </div>					    
				    <div class="layui-form-item">
				    	<div class="layui-inline">
					    	<label class="layui-form-label">建安工程费（万元）</label>
				      		<div class="layui-input-inline">
				        		<input type="text" id="id_costCae" name="costCae" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
							<label class="layui-form-label">总包单位</label>
							<div class="layui-input-inline">
								<input type="hidden" id="id_sgCoopId" name="sgCoopId" >
								<input type="text" id="id_sgCoopName" name="sgCoopName" readonly="readonly" style="border:0px;width:220px" class="layui-input">									
							</div>
						</div>
					    <div class="layui-inline">
							<label class="layui-form-label" >居间方 </label>
							<div class="layui-input-inline">
								<input type="text" id="id_linkPower" name="linkPower" readonly="readonly" style="border:0px" class="layui-input">
							</div>
						</div>
					</div>			  	
		  		</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset"  id="beforeToolInfo">
				<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">开工前管理工具明细  ></legend>
				<div style="margin-top:20px">																					
					<div class="contract-box" id="tool-list">
        				<div class="contract-money">
            				<table class="layui-table">
			                    <colgroup>
			                        <col width="290">
			                        <col width="500" >
			                        <col width="500" >
			                        <col width="500" >
			                    </colgroup>
								<thead>
									<tr>
										<th>序号</th>
										<th>内容</th>
										<th>备注</th>
										<th>附件<br>支持pdf、excel、word、图片资料，可上传多个</th>
									</tr>
								</thead>
								<tbody>
									<tr> 
										<td><input type="text" value="1" name="showIdxDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>
										<td><input type="text" value="18项重点工作" name="itemNameDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>										
										<td><input type="text" value="" maxlength="100" name="itemMemoDetail" autocomplete="off" lay-verify="required" class="layui-input"/></td>
										<td><div class="layui-upload"><a class="uploadA" id="1-upload-more" name="showIdxAtt" href="javascript:void(0);" >上传</a>
											<div class="layui-upload-list" id="1-upload-more-list" ></div></div>
										</td>								 						
									</tr>
									<tr> 
										<td><input type="text" value="2" name="showIdxDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>
										<td><input type="text" value="六先六快" name="itemNameDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>										
										<td><input type="text" value="" maxlength="100" name="itemMemoDetail" autocomplete="off" lay-verify="required" class="layui-input"/></td>
										<td><div class="layui-upload"><a class="uploadA" id="2-upload-more" name="showIdxAtt" href="javascript:void(0);" >上传</a>
											<div class="layui-upload-list" id="2-upload-more-list" ></div></div>
										</td>								 						
									</tr>
									<tr> 
										<td><input type="text" value="3" name="showIdxDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>
										<td><input type="text" value="与政府界面划分" name="itemNameDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>										
										<td><input type="text" value="" maxlength="100" name="itemMemoDetail" autocomplete="off" lay-verify="required" class="layui-input"/></td>
										<td><div class="layui-upload"><a class="uploadA" id="3-upload-more" name="showIdxAtt" href="javascript:void(0);" >上传</a>
											<div class="layui-upload-list" id="3-upload-more-list" ></div></div>
										</td>								 						
									</tr>
									<tr> 
										<td><input type="text" value="4" name="showIdxDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>
										<td><input type="text" value="与总包界面划分" name="itemNameDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>									
										<td><input type="text" value="" maxlength="100" name="itemMemoDetail" autocomplete="off" lay-verify="required" class="layui-input"/></td>
										<td><div class="layui-upload"><a class="uploadA" id="4-upload-more" name="showIdxAtt" href="javascript:void(0);" >上传</a>
											<div class="layui-upload-list" id="4-upload-more-list" ></div></div>
										</td>								 						
									</tr>
									<tr> 
										<td><input type="text" value="5" name="showIdxDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>
										<td><input type="text" value="现场策划" name="itemNameDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>											
										<td><input type="text" value="" maxlength="100" name="itemMemoDetail" autocomplete="off" lay-verify="required" class="layui-input"/></td>
										<td><div class="layui-upload"><a class="uploadA" id="5-upload-more" name="showIdxAtt" href="javascript:void(0);" >上传</a>
											<div class="layui-upload-list" id="5-upload-more-list" ></div></div>
										</td>								 						
									</tr>
									<tr> 
										<td><input type="text" value="6" name="showIdxDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>
										<td><input type="text" value="开工前策划案" name="itemNameDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>											
										<td><input type="text" value="" maxlength="100" name="itemMemoDetail" autocomplete="off" lay-verify="required" class="layui-input"/></td>
										<td><div class="layui-upload"><a class="uploadA" id="6-upload-more" name="showIdxAtt" href="javascript:void(0);" >上传</a>
											<div class="layui-upload-list" id="6-upload-more-list" ></div></div>
										</td>								 						
									</tr>
									<tr> 
										<td><input type="text" value="7" name="showIdxDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>
										<td><input type="text" value="综合计划" name="itemNameDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>											
										<td><input type="text" value="" maxlength="100" name="itemMemoDetail" autocomplete="off" lay-verify="required" class="layui-input"/></td>
										<td><div class="layui-upload"><a class="uploadA" id="7-upload-more" name="showIdxAtt" href="javascript:void(0);" >上传</a>
											<div class="layui-upload-list" id="7-upload-more-list" ></div></div>
										</td>								 						
									</tr>
									<tr> 
										<td><input type="text" value="8" name="showIdxDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>
										<td><input type="text" value="总包团队面试" name="itemNameDetail" readonly="readonly" style="border:0px;text-align:center" class="layui-input" /></td>											
										<td><input type="text" value="" maxlength="100" name="itemMemoDetail" autocomplete="off" lay-verify="required" class="layui-input"/></td>
										<td><div class="layui-upload"><a class="uploadA" id="8-upload-more" name="showIdxAtt" href="javascript:void(0);" >上传</a>
											<div class="layui-upload-list" id="8-upload-more-list" ></div></div>
										</td>								 						
									</tr>								
			                	</tbody>
		                	</table>
               			</div>                									
					</div>
				</div>
			</fieldset>
			<div class="layui-form-item" style="position: fixed ! important; right: 30px; bottom:45%;z-index:10000;">
				<div class="layui-input-block">
		      		<button class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius" type="button" lay-submit lay-filter="addInfo_form_submit" id="addInfo_form_submit">
		      		<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>
		      		提交
		      		</button>
		      	</div>
		    </div>
		</form>
  		</div>
	</div>
</div>
<script>
  	String.prototype.format = function () {
		var model = arguments;
	    return this.replace(/\{(\d+)\}/g, function (s, i) { 
	        return !!model[i]?model[i]:'';
	    });
	}
	//静态资源路径前缀
	var staticPath = '${fileHttpPre}';
	var stateJSON = <infopub:dicJson groupNo="A00010028" />;
	
  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set', 'upload', 'element', 'laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,element = layui.element
    ,laydate = layui.laydate
    ,upload = layui.upload;
    
 	// 正则校验
	form.verify({
		//验证汉字
	    CHS:[
	    	/^[\u0391-\uFFE5]+$/
	    	,'只能输入汉字'
	  	],
	  	//大于0的正整数
	  	intNumber:[
			/^[1-9]\d*$/
			,'请输入正确的数字'
	  	],
	  	//数字只能有两位小数
	  	floatNumber:[
			/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			,'请输入正确的数字'
	  	],
	  	//数字大于等于0，并只能有两位小数
	  	floatAmount:[
			/^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
			,'请输入正确的数字'
	  	]
	});
	
	uploadRender(1,upload,$);
	uploadRender(2,upload,$);
	uploadRender(3,upload,$);
	uploadRender(4,upload,$);
	uploadRender(5,upload,$);
	uploadRender(6,upload,$);
	uploadRender(7,upload,$);
	uploadRender(8,upload,$);
	
	//项目名称select监听
    form.on('select(add_select_proId)', function(data){
    	var id = data.value;
    	if(id == null || id == ''){
    		$("#id_sgCityId").val('');
			$("#id_sgCityName").val('');
			$("#id_costCae").val('');
			$("#id_sumAmount").val('');
			$("#id_linkPower").val('');
			$("#id_sgCoopId").val('');
			$("#id_sgCoopName").val('');
    		return;
    	}
    	
    	//通过项目名称带出所需要的的数据
		$.ajax({
			type : "POST", //提交方式  
			url : "${ctx}/beforeTool/getBeforeToolById",//路径  
			data : {
				"proCodeAndCodes" :id
			},//数据，这里使用的是Json格式进行传输  
			success : function(result) {//返回数据根据结果进行相应的处理 
				if(result.flag==true){
					if(result.discloseProVo!=null){	
						//交底带出数据
						if(result.discloseProVo.sgCityId!=null&&result.discloseProVo.sgCityId!=''){
							$("#id_sgCityId").val(result.discloseProVo.sgCityId);
							$("#id_sgCityName").val(result.discloseProVo.sgCityName);
						}else{
							$("#id_sgCityId").val('');
							$("#id_sgCityName").val('');
						}
						if(result.discloseProVo.costCae!=null&&result.discloseProVo.costCae!=''){
							$("#id_costCae").val(result.discloseProVo.costCae);
						}else{
							$("#id_costCae").val(0);
						}
						if(result.discloseProVo.sumAmount!=null&&result.discloseProVo.sumAmount!=''){
							$("#id_sumAmount").val(result.discloseProVo.sumAmount);
						}else{
							$("#id_sumAmount").val(0);
						}
						if(result.discloseProVo.linkPower!=null&&result.discloseProVo.linkPower!=''){
							$("#id_linkPower").val(result.discloseProVo.linkPower);
						}else{
							$("#id_linkPower").val('');
						}
						//带出内部协议总包单位
						if(result.discloseProVo.sgCoopId!=null&&result.discloseProVo.sgCoopId!=''){
							$("#id_sgCoopId").val(result.discloseProVo.sgCoopId);
							$("#id_sgCoopName").val(result.discloseProVo.sgCoopName);
						}else{
							$("#id_sgCoopId").val('');
							$("#id_sgCoopName").val('');
						}
						form.render();
					}else{
						layer.msg('数据通信异常~',{icon: 0});
					}
				}				
			} 
		});
	});
 	
   	//监听提交
  	form.on('submit(addInfo_form_submit)', function(data){  		
  		$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
  		layer.load();
       	//提交 Ajax 成功后，静态更新表格中的数据
       	$.ajax({
           	type : 'post',
			url : basePath + '/beforeTool/save',
           	data: $('#addInfo_form').serialize(),
			success:function(result){
				if(result.success){
					layer.closeAll('loading'); //关闭loading
					layer.msg('提交单据成功~',{icon: 1});
					//两秒后关闭当前页面
					setTimeout(function(){
						/**
						 * 查找父菜单，并刷新
						 */
						var topDoc = $(window.top.document);
						var path = basePath + '/beforeTool/list';
						// 获取页面名称
						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
						if(name == '' || name == null){
							name = '开工前管理工具审批';
						}
						window.parent.layui.index.openTabsPage(path, name);
						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
						iframe[0].contentWindow.location.reload(true);
						
						/**
						 * 关闭当前页
						 */
						var currPath = basePath + '/beforeTool/add';
						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
				        }, 2000);
				}else{
					layer.closeAll('loading'); //关闭loading
  					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
					layer.msg(result.msg,{icon: 7});
			  	}
			}
       	});
   	});  
 	// data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  	
  });

	//删除文件
   function del(index){
	 layui.$("#upload_img_"+index).remove();
   }
  
	//根据url查看文件
	function showImg(url){
		var openWin = window.open(url,'','left=410,height=768, width=1024, top=200,  toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
	}
	
	//子项附件
  	var uploadRender = function(id,upload,$) {
		upload.render({
			elem : '#' + id + '-upload-more'
			,url : basePath + '/beforeTool/uploadAtt/'
			,data : {
				types : id
			}
			,multiple : true
			,accept : 'file'
			,acceptMime : 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf'
			,before : function(obj) {
				layer.load();
			}
			,done : function(res) {
				if (res.code > 0) {
					layer.closeAll('loading');
					return layer.msg(res.msg, {
						icon : 7
					});
				}
				if (res.entity != null && res.entity.length > 0) {
					for ( var i in res.entity) {						
						var beforeTool = res.entity[i];
						var arr = beforeTool.split("|");
						var imgSrc = "";
						var suffix = arr[1].substring(arr[1].lastIndexOf(".") + 1, arr[1].length);
						if (suffix == 'jpg' || suffix == 'png') {
							imgSrc = "${fileHttpPre}/" + arr[3];
						} else {
							imgSrc = "${ctx}/resources/images/" + suffix + ".jpg";
						}
						
						var $uploadList = $('#' + id + '-upload-more-list');
						$uploadList.append('<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'" ><img src="'+imgSrc+'" title="'+ arr[1] +'" class="layui-upload-img" /><div class="mask" ><a href="javascript:void(0)" onclick="showImg(\''
							+ "${fileHttpPre}"
							+ arr[3]
							+ '\');" >查看</a><a href="javascript:void(0)" onclick="del(\''
							+ arr[2]
							+ '\')"; >删除</a></div><p>'
							+ arr[1]
							+ '</p><input name="showIdxAtt" value="" type="hidden" /><input style="display:none;" value="'+beforeTool+'"  name="fileAtts1" /></div>');
						
						var $tr = $uploadList.parents('tr');
						var rowId = $tr.find('input[name="showIdxDetail"]').val();											
						$uploadList.find('input[name="showIdxAtt"]').val(rowId);					
					}
				}
			}
			,allDone : function(obj) {
				layer.closeAll('loading');
			}
			,error : function() {
				layer.closeAll('loading');
				layer.msg("上传失败，请稍后再试~", {
					icon : 7
				});
			}
		});
	}
  </script>
</body>
</html>

